package com.lht.leetcodeDemo;

import java.util.Arrays;
import java.util.Collections;
import java.util.Comparator;
import java.util.List;
import java.util.stream.Collectors;

/**
 * @author Eric
 * @version 1.0
 * @date 2019-06-04
 */
public class LargestNumber {

    public static void main(String[] args) {
        int[] arr = new int[]{3, 30, 34, 5, 9};
        System.out.println(new LargestNumber().largestNumber(arr));
    }

    public String largestNumber(int[] nums) {
        StringBuilder count = new StringBuilder();
        for (String s : Arrays.stream(nums).boxed().map(Object::toString).sorted((o1, o2) -> (o2 + o1).compareTo(o1 + o2)).collect(Collectors.toList())) {
            count.append(s);
        }
        String result = count.toString();
        return result.startsWith("0") ? "0" : result;
    }
}
